# 使用官方 Python 基础镜像
FROM python:3.10-alpine

# 设置工作目录
WORKDIR /opt/idcops

# 复制项目文件到容器中
COPY . /opt/idcops

# 使用阿里云镜像源
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories

# 安装系统依赖
RUN apk add --no-cache \
    tzdata \
    curl \
    build-base \
    libffi-dev \
    python3-dev \
    sqlite-dev \
    mysql-dev \
    mariadb-dev \
    jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev \
    tiff-dev tk-dev tcl-dev harfbuzz-dev fribidi-dev jpeg g++

# 升级 pip 并安装 Python 依赖
RUN pip install -U pip setuptools wheel -i https://pypi.tuna.tsinghua.edu.cn/simple || \
    pip install -U pip setuptools wheel && \
    pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple || \
    pip install -r requirements.txt

# 设置时区
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
    echo "Asia/Shanghai" > /etc/timezone

# 复制 entrypoint.sh 到容器中
COPY config/entrypoint.sh /entrypoint.sh

# 给予 entrypoint.sh 执行权限
RUN chmod +x /entrypoint.sh

# 暴露端口
EXPOSE 8000

# 设置 entrypoint
ENTRYPOINT ["/entrypoint.sh"]

# 创建必要的目录
RUN mkdir -p /opt/idcops/run
RUN mkdir -p /opt/idcops/cache